package com.ruoyi.framework.config;

import com.ruoyi.common.config.JoConfig;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 业务 环境配置项加载
 *
 * @author Jyl
 */
@Log4j2
@Component
@Order(1001)
public class JoCommandLineRunner implements CommandLineRunner
{
    @Autowired
    private ISysConfigService sysConfigService;
    @Autowired
    private JoConfig joConfig;

    @Override
    public void run(String... args) throws Exception
    {
        //刷新为数据库系统配置参数
        List<SysConfig> list = sysConfigService.selectConfigList(new SysConfig());
        for (SysConfig sysConfig : list)
        {
            log.info("[{}]:{})({}", "Order(1001)", sysConfig.getConfigKey(), sysConfig.getConfigValue());
            if (sysConfig.getConfigKey().equals("sys.login.repeat"))
            {
                joConfig.setRepeat(sysConfig.getConfigValue());
            }
            if (sysConfig.getConfigKey().equals("sys.login.udid"))
            {
                joConfig.setUdid(sysConfig.getConfigValue());
            }
        }
    }
}
